package cn.yangliu.webflux.comm;

import java.time.LocalDateTime;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.ToStringSerializer;
import lombok.Getter;
import org.hibernate.annotations.GenericGenerator;

/**
 * @author 杨柳
 * @date 2019-05-15
 */
@MappedSuperclass
@Getter
public class BaseEntity<T, ID> {

//    @Id
//    @GeneratedValue(strategy = GenerationType.IDENTITY)

    @Id
    @GeneratedValue(generator = "idGenerator")
    @GenericGenerator(name = "idGenerator", strategy = "cn.yangliu.webflux.tools.IdGenerator")
    @JSONField(serializeUsing = ToStringSerializer.class)
    protected ID id;

    @Column(name = "create_time")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    protected LocalDateTime createTime;

    @Column(name = "update_time")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    protected LocalDateTime updateTime;

    @Column(name = "remark")
    private String remark;

    public T setId(ID id) {
        this.id = id;
        return (T) this;
    }

    public T setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
        return (T) this;
    }

    public T setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
        return (T) this;
    }

    public T setRemark(String remark) {
        this.remark = remark;
        return (T) this;
    }
}
